package org.gpf.singleton;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class SingletonTest implements Runnable{

	public static void main(String[] args) throws IOException {
		
//		System.out.println("单态模式的锇汉式实现【线程安全】");
//		System.out.println("单态模式的懒汉式实现【非线程安全】");
//		System.out.println("使用同步方法改进懒汉式实现【线程安全，效率不高】");
//		System.out.println("使用同步代码块和双重检查改进懒汉式实现【线程安全，效率比同步方法高】");
		// System.out.println("通过反射机制使所有的单态模式失效！");
		
		// new Thread(new SingletonTest()).start();
		// new Thread(new SingletonTest()).start();
		// new Thread(new SingletonTest()).start();
		// new Thread(new SingletonTest()).start();
		// new Thread(new SingletonTest()).start();
		// new Thread(new SingletonTest()).start();
		
		Process process = Runtime.getRuntime().exec("ping.exe baidu.com -t");
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				process.getInputStream()));
		String line;
		while ((line = reader.readLine()) != null) {
			System.out.println(line);
		}
		reader.close();
	}

	@Override
	public void run() {
		
//		Singleton1 singleton1 = Singleton1.getInstance();
//		System.out.println(singleton1); // 打印对象的hash码
		
//		Singleton2 singleton2 = Singleton2.getInstance();
//		System.out.println(singleton2);
		
//		Singleton3 singleton3 = Singleton3.getInstance();
//		System.out.println(singleton3);
		
//		Singleton4 singleton4 = Singleton4.getInstance();
//		System.out.println(singleton4);
		
		/* 通过反射使所有的单态模式失效 */
		// try {
		// // 取得该类的Class对象
		// Class<?> c = Class.forName("org.gpf.singleton.Singleton1");
		// Constructor<?> c0 = c.getDeclaredConstructor(); // 取得该类的无参构造
		// c0.setAccessible(true); // 设置改构造器是可见的
		// Singleton1 singleton1 = (Singleton1) c0.newInstance(); // 通过构造器实例化对象
		// System.out.println(singleton1);
		// } catch (ClassNotFoundException e) {
		// e.printStackTrace();
		// } catch (InstantiationException e) {
		// e.printStackTrace();
		// } catch (IllegalAccessException e) {
		// e.printStackTrace();
		// } catch (NoSuchMethodException e) {
		// e.printStackTrace();
		// } catch (SecurityException e) {
		// e.printStackTrace();
		// } catch (IllegalArgumentException e) {
		// e.printStackTrace();
		// } catch (InvocationTargetException e) {
		// e.printStackTrace();
		// }

		// Singleton5 singleton05 = Singleton5.getInstance();
		// System.out.println(singleton05);

		// Singleton6 singleton6 = Singleton6.getInstance();
		// System.out.println(singleton6);

		// Singleton7 singleton7 = Singleton7.INSTANCE;
		// System.out.println(singleton7);
	}

}
